/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package fr.ove.openmath.jome.ctrl.amto;

/**
 *
 * @author Mr.Sam
 */
import fr.ove.openmath.jome.ctrl.linear.events.LinearParserEvent;
import fr.ove.openmath.jome.ctrl.amto.AbstractMathTreeObject;

/**
* The abstract math tree object of a n-ary operator.
*
* @author © 1999 DIRAT Laurent
* @version 1.0  18/11/1999
*/
public abstract class MapsToNAry extends AbstractMathTreeObject {
    /**
    * The constructor.
    * @param identifier the identifier of the instance.
    * @param token the identifier of the instance by the mean of the event sent.
    */
    public MapsToNAry(String identifier, int token) {
        super(identifier, token);
    }

    /**
    * "Flushes" the object as a sequence of events for the building of the model
    */
    public void flush() {
        LinearParserEvent linearParserEvent = new LinearParserEvent(getEventSource());
        
        int nbChildren = getNbChildren();
        if (nbChildren == 0) {
            linearParserEvent.setToken(token, param);
            fireLinearParserEvent(linearParserEvent);
        }
        else {
            for (int i = 0; i < nbChildren; i++) {
                flushChild(getChild(i), i);
                if (i < (nbChildren - 1)) {
                    linearParserEvent.setToken(token, param);
                    fireLinearParserEvent(linearParserEvent);
                }
            }
        }
    }
}